package com.controller;

import com.domain.User;
import com.github.pagehelper.PageHelper;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/demo")
//@EnableAutoConfiguration
public class SampleController {

    @Autowired
    UserService userService;

    @RequestMapping("/index")
    public String index() {
        return  "index";
    }

    @RequestMapping("/getUser")
    public String getUser(Model model, User user) {
        List<User> userlist =  userService.listUser();
        return  userlist.toString();
    }

    /**
     *
     * @return
     */
    @RequestMapping("/addAge")
    public Object addAge(){
        try {
            userService.addAge();
        }catch (Exception e){
            return  "error ! !"+userService.listUser();
        }
        return userService.listUser();
    }

    /**
     * 翻页查询
     * @param pageNum
     * @return
     */
    @RequestMapping("/findUser")
        public Object findUser(int pageNum){
        PageHelper.startPage(pageNum,10);
        List<User> user = userService.findUser(pageNum);
        return user;
    }
}
